/* 
 * Modbus app for RTU.
 * Copyright (c) 2012  apleilx
 * All rights reserved.
 * no limite
 */

/* ----------------------- Platform includes --------------------------------*/
#define _MBAPP_MODULE_
#include "mbapp.h"
#include "osObjects.h"                                          // RTOS object definitions

uint16_t DataRecevie[32];

uint8_t mbTestErrCnt = 0;
uint8_t mbTestOkCnt = 0;
uint32_t mbCnt;
uint32_t TickTimeCnt;
extern uint32_t uwTick;

void mbTestCallBack(uint8_t CmdSite, uint8_t ErrSt);
void mbsimulink(char mbid);

/*****************************************************************************//*!
* @brief   	Slave device handle.
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/    
void mbTask(void const *argument)
{
    uint32_t MbCnt=0;
    
    mbyInit(MB_RTU_SLAVE, 9600, MB_PAR_EVEN);
    mbyObj.SlaveId=2;
    mbzInit(MB_RTU_SLAVE, 9600, MB_PAR_EVEN);
    mbzObj.SlaveId=2;
    
    TickTimeCnt = uwTick;
    
    /*
    if(mbzObj.RunSt.bits.MasterMode)
    {
        mbStaticCmdSet(&mbzObj, 0, 2, FUN_CODE_READ_REG, DataRecevie, 0x10, 8, 0);
        mbStaticCmdSet(&mbzObj, 1, 2, FUN_CODE_READ_REG, DataRecevie, 0x10, 6, 0);
    }
    */
    
    for(;;){
        MbCnt++;

        osDelay(2);
        mbSlavePoll(&mbyObj);
        mbSlavePoll(&mbzObj);
    }
}


/*****************************************************************************//*!
* @brief   	modbus simulink.
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/  
void mbsimulink(char mbid)
{
    regDevice = 0x5000;
    regVersion = 0x1000;

}
